#pragma once

#include<stdint.h>
#include<functional>

class myepoll;
class EventLoop;

//使用通道用于管理每个文件描述符
class MyChannel
{
private:
    /* data */
    int fd;
    // myepoll *ep;
    EventLoop *loop;
    //注册事件类型
    uint32_t events;
    //就绪事件类型
    uint32_t revents;
    bool inEpoll;
    //读回调函数
    std::function<void()> readcallBack;
    //写回调函数
    std::function<void()> writecallBack;
    bool flagReadorWrite = true;

public:
    MyChannel();
    MyChannel(EventLoop *_loop,int _fd);
    ~MyChannel();

    int getFd();
    void enableReading();
    void enableWriting();
    uint32_t getEvents();
    uint32_t getRevents();
    bool getInEpoll();
    void setInEpoll();
    void setInEpoll(bool falg);
    
    void setRevents(uint32_t ev);

    void headleEvent();
    void setReadCallBack(std::function<void()>);
    void setWriteCallBack(std::function<void()>);
};

